package chapter17.HomeWork;

import java.util.Scanner;

/**
 * @Auther: Tx
 * @Date: 2022/7/13 16:07
 */
//一个线程随机输出1-100，直到另一个线程输入Q
public class HomeWork01 {
    public static void main(String[] args) {
        Print print = new Print();
        print.setDaemon(true);
        ReadQ readQ = new ReadQ();
        print.start();
        readQ.start();
    }
}
class Print extends Thread{
    @Override
    public void run() {
        while (true){
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("随机输出数字1-100---"+(int)(Math.random()*100));
        }
    }
}
class ReadQ extends Thread{
    private String value = "";
    @Override
    public void run() {
        while (!(value.equals("Q"))){
            Scanner scanner = new Scanner(System.in);
            System.out.println("输入Q结束");
            value = scanner.next();
        }
    }
}
